# env
import os
import sys
import ctypes
sys.path.append(os.getcwd())

import cv2
import time
from codes.selector import AreaSelector
from codes.recognizer import PatternRecognizer
from codes.operator import MouseOperator
from codes.logics import Logics


def main():
    # pic = cv2.imread("res/shot1.png")
    selector = AreaSelector()
    coords, pic = selector.wait_select()
    # print("selector result:", coords)

    # cv2.imshow('Detected', pic)
    # cv2.waitKey(0)
    # cv2.destroyAllWindows()

    recognizer = PatternRecognizer()
    recognizer.set_patterns({
        1: "res/1.png",
        2: "res/2.png",
        3: "res/3.png",
        4: "res/4.png",
        5: "res/5.png",
        6: "res/6.png",
        7: "res/7.png",
        8: "res/8.png",
        9: "res/9.png",
    })
    res = recognizer.run(pic)
    for i in range(0, 9):
        print("cnt", i+1, len(res[i+1]))

    _operator = MouseOperator()
    _operator.set_offset(coords[0], coords[1])

    logic = Logics()
    logic.set_operator(_operator)
    logic.start(res)

    # for p in res["6"]:
    #     _operator.move_to(p[0], p[1])
    #     time.sleep(0.6)


if __name__ == "__main__":
    main()
